package com.shundr.shipper.user.model;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shundr.shipper.R;
import com.shundr.shipper.common.util.DateUtil;

/**
 * 积分记录
 * IntegralAdapter
 * 
 * @author larry 2015-7-2 下午2:36:51 
 * @version 1.0.0
 *
 */
public class IntegralAdapter extends BaseAdapter{
	public List<IntegralInfo> mList;
	private Context mContext;

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int index) {
		return mList.get(index);
	}

	@Override
	public long getItemId(int id) {
		return id;
	}

	public IntegralAdapter(List<IntegralInfo> list, Context mContext) {
		super();
		this.mList = list;
		this.mContext = mContext;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {
		ViewHold viewHold = null;
		if(convertView == null){
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_integral,null);
			viewHold = new ViewHold();
			viewHold.tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
			viewHold.tvIntegral = (TextView) convertView.findViewById(R.id.tv_integral);
			viewHold.tvTime = (TextView) convertView.findViewById(R.id.tv_time);
			convertView.setTag(viewHold);
		}else{
			viewHold = (ViewHold) convertView.getTag();
		}
		try {
			final IntegralInfo info = mList.get(position);
			viewHold.tvTitle.setText(info.getIntegralName());
			if (info.getIntegralNum() > 0) {
				viewHold.tvIntegral.setText("+" + info.getIntegralNum());
			} else {
				viewHold.tvIntegral.setText(info.getIntegralNum() + "");
			}
			viewHold.tvTime.setText(DateUtil.getInterval(info.getIntegralTime()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return convertView;
	}

	static class ViewHold{
		TextView tvTitle;
		TextView tvIntegral;
		TextView tvTime;
	}
}
